package labox.innovation.gameserver.instancemanager;

import java.util.Collection;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javolution.util.FastMap;
import labox.innovation.gameserver.model.L2Transformation;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 *
 * @author  KenM
 */
public class TransformationManager {
	
	private static final Logger _log = LoggerFactory.getLogger(TransformationManager.class.getName());

	public static TransformationManager getInstance() {
		return SingletonHolder._instance;
	}

	private Map<Integer, L2Transformation> _transformations;

	private TransformationManager() {
		_transformations = new FastMap<Integer, L2Transformation>();
	}

	public void report() {
		_log.info("Loaded: " + this.getAllTransformations().size() + " transformations.");
	}

	public boolean transformPlayer(int id, FuzePcInstance player) {
		L2Transformation template = this.getTransformationById(id);
		if (template != null) {
			L2Transformation trans = template.createTransformationForPlayer(player);
			trans.start();
			return true;
		} else {
			return false;
		}
	}

	public L2Transformation getTransformationById(int id) {
		return _transformations.get(id);
	}

	public L2Transformation registerTransformation(L2Transformation transformation) {
		return _transformations.put(transformation.getId(), transformation);
	}

	public Collection<L2Transformation> getAllTransformations() {
		return _transformations.values();
	}

	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder {
		protected static final TransformationManager _instance = new TransformationManager();
	}
}
